import datetime
import logging
from config import conf
import os

members =[]
isGroup = False
# 所有的人
all_members = conf().get("members",[])
content = []
# 初始化日报

# 设置日志记录器
record_file = 'record/{}.txt'.format(datetime.date.today())

# 判断文件是否存在，如果不存在则创建
if not os.path.exists(record_file):
    with open(record_file, 'w'):
        pass

# 更新标识
def update_day_report_flag(flag):
    global isGroup
    isGroup = flag

# 获取标识
def get_day_report_flag():
    global isGroup
    return isGroup

# 新增完成名单
def add_finished_user(user):
    try:
        with open(record_file, 'a') as file:
            file.write(user + '\n')
        print("内容已成功写入文件。")
    except IOError:
        print("写入文件时发生错误。")


# 初始化日报


def get_day_report():
    global members
    # 从文件获取名单
    with open(record_file, 'r') as file:
        for line in file:
            members.append(line.strip())
    members = list(set(members))
    # 未完成的名单
    not_finished_members = [x for x in all_members if x not in members]
    result = '{}日报统计:\n\n'.format(datetime.date.today())
    result += '\n'.join(f'{i+1}. {item}' for i, item in enumerate(members))
    result += '\n\n 未完成的名单:\n\n'
    result += '\n'.join(f'{i+1}. {item}' for i, item in enumerate(not_finished_members))
    return result



